<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<title>组织机构编辑页面</title>
<link href="<%=request.getContextPath()%>/css/Default.css"
	rel="stylesheet" type="text/css" />
	<link href="<%=request.getContextPath()%>/css/redmond/jquery-ui-1.8.14.custom.css"
	rel="stylesheet" type="text/css"></link>
<link href="<%=request.getContextPath()%>/css/Dialog.css"
	rel="stylesheet" type="text/css"></link>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="<%=request.getContextPath()%>/scripts/jquery-1.5.1.min.js"
	type="text/javascript"></script>
	<script src="<%=request.getContextPath()%>/scripts/HRM.js" type="text/javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/jquery-ui-1.8.14.min.js"
	type="text/javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/jquery.validate.min.js"
	type="text/javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/jquery.validate.message_cn.js"
	type="text/javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/Dialog.js"
	type="text/javascript"></script>
		<script
	src="<%=request.getContextPath()%>/scripts/jstree/jquery.jstree.js"
	type="text/javascript"></script>
<script
	src="<%=request.getContextPath()%>/scripts/Menu.js"
	type="text/javascript"></script>
</head>
<body class="dialogBody">
<script type="text/javascript">
$().ready(function(){
	$("#upName").die('focus').live('focus',function(){
		$("#groupTree").show().css({"position":"absolute",top:$(this).offset().top+23,left:$(this).offset().left});
		initGroupTree();
	});
});
function initGroupTree(){
	$("#groupTree").jstree({//组织机构树
        "json_data" : {
            "ajax" : {
                "url" : "<%=request.getContextPath()%>/group.do?method=getGroupTree",
				"data" : function(n) {
						}
					},
				'success':function(data){
					console.log(data);
					}
				},
			"plugins" : [ "themes",
				"json_data" ,"ui"]
	}).bind("select_node.jstree", function (event, data) {
		if(data.rslt.obj.attr("id")==''){
			return false;
		}else{
			$("#upid").val(data.rslt.obj.attr("id"));
			var upName=$(data.rslt.obj.find("a").get(0)).text();
			$("#upName").show().val(upName);
			$("#groupTree").html("").hide();
		}
	});
	$("#groupTree").bind("loaded.jstree", function (e, data) {
		//$($('.jstree-leaf').find('a').get(0)).click();//默认选中树的第一个子项
		//$(DOM对象).get(i)返回的是一个DOM对象，不能直接调用click方法，但是在Firefox中不报错，在Chrome中则会出现点击事件不响应的现象
	});
}
	</script>
<script type="text/javascript">
function beforeFormSubmitFunc(){
	if(!$("#groupEditForm").valid()){
		createAlertDialog('提示信息','还有未正确填写的项，请参照提示修改!');
		return false;
	}else{
		return true;
	}
}
$().ready(function(){
	$("#groupEditForm").validate({
		rules:{
			groupName:{
				required:true,
				maxlength:20
			},
			groupDesc:{
				maxlength:500
			}
		},
		errorPlacement:function(error,element){
			createTooltip(error,element);
		},
		success:function(error){
			sucRemoveTooltip(error);
		},
		event:'blur'|'keyup'|'focus'|'keydown'
	});
	$('#groupEditForm').find("input").focus(function(){
		$(this).valid();
	});
	$('#groupEditForm').find("input").blur(function(){
		$('#'+$(this).attr('id')+'Error').remove();
	});
	$('#groupEditForm').find('#groupName').focus();
});
</script>
	<form id="groupEditForm" action='<%=request.getContextPath()%>/group.do?method=updateGroupById' method="post">
	<center>
		<table width="100%" height="" align="center" cellpadding="2"
			cellspacing="0">
			<tr>
				<td height="10"></td>
				<td><input name="id" type="hidden" value='<c:out value="${group.id}" />'
									id="id" /></td>
			</tr>
			<tr>
				<td>
				<center>
					<fieldset>
						<legend>
							<label>组织机构信息</label>
						</legend>
						<table width="100%" border="0" cellpadding="0" cellspacing="0">
							<tr>
								<td height="30" align="right">组织机构：</td>
								<td><input name="departmentName" type="text" value='${group.departmentName}'
									id="departmentName" /><span class='requiredSpan'>*</span></td>
							</tr>
							<tr>
								<td height="30" align="right">机构电话：</td>
								<td><input name="telephone" type="text" value="${group.telephone}"
									id="telephone" /></td>
							</tr>
<!-- 							如果是顶级机构，不能设置其上级机构 -->
							<c:if test="${group.upid!=-1}">
							<tr>
								<td height="30" align="right">上级机构：</td>
								<td><div><input type='hidden' id='upid' name='upid' value="${group.upid}"/><input style='float:left;' type='text' id='upName' name='upName' value="${group.parentGroup.departmentName}" readonly style='display:block;'/><span class='requiredSpan'>*</span></div><div class="treeItem" id="groupTree" style="width:180px;display:none;"></div></td>
							</tr>
							</c:if>
							<tr>
								<td height="30" align="right" valign='top'>备注：</td>
								<td><textarea name="description" id="description"
										style="width: 118px; height: 60px;">${group.description}</textarea></td>
							</tr>
						</table>
					</fieldset>
					</center>
				</td>
			</tr>
		</table>
		</center>
	</form>

</body>
</html>